*set directory to location where save data file
**also, be sure to install qcount:  https://ideas.repec.org/c/boc/bocode/s456714.html

cd "\\ppd3.sppd.usc.edu\users$\pmccann\Desktop"
pwd
use "psrm_replication_file.dta" , clear
log using "psrm_replication.smcl", name("Clouser McCann Shipan MS") replace


****Table 1:
tab countagents3 if year<2017 & lawcounter==1, freq

****Figure 1:
scatter countagents_perlaw year if year<2017, scale(1.1) xlabel(1947(2)2016 ,  valuelabel angle(90) labsize(vsmall) )  xti("Year") yti("Num. Agencies by Law") ms(oh) mcolor(gs10) mlwidth(vthin) mlabel(label2) mlabs(vsmall) mlabpos(9) mlabc(black) mlabstyle(p1)
graph save "figure1.gph", replace
*and:
list year pln lawtitle countagents if year<2017 & lawcounter==1 & countagents>30


***decades numbers for page 10:
gen decades = .
replace decades = 1 if year>=1947 
replace decades = 2 if year>=1960 
replace decades = 3 if year>=1970 
replace decades = 4 if year>=1980 
replace decades = 5 if year>=1990 
replace decades = 6 if year>=2000 
replace decades = 7 if year>=2010 
replace decades = . if year>=2017
tab decades
bysort decades:  egen countbard = mean(countagents_perlaw)
bysort decades:  egen countmedd = median(countagents_perlaw)
label define decade1_lbl 1 "1947-1959" 2 "1960-1969" 3 "1970-1979" 4 "1980-1989" 5 "1990-1999" 6 "2000-2009" 7 "2010-2016" 
label values decades decade1_lbl
tab  decades countbard 
tab decades countmedd 

*footnote 22:
***for regression in footnote 22
bysort congress:  egen countbarc = mean(countagents_perlaw)
bysort congress:  egen countmedc = median(countagents_perlaw) 
bysort congress:  egen countsdc = sd(countagents_perlaw) 

reg countsdc yr_45 if year<2017 & lawcounter==1, vce(robust)

*Table 2:
tabulate divided countagents3 if year<2017 & lawcounter==1,  freq
ttest countagents if year<2017 & lawcounter==1 & nondelegation==0, by(divided)
*footnote 23:
reg countagents divided c.yr_45##c.yr_45 if year<2017 & lawcounter==1, vce(robust)
reg countagents_perlaw divided c.yr_45##c.yr_45 if year<2017 & lawcounter==1, vce(robust)
reg median_count divided c.yr_45##c.yr_45 if year<2017 & lawcounter==1, vce(robust)

****qcount regression:
eststo q10:  qcount countagents divided yr_45 yr_sq   if lawcounter==1 & year<2017, q(0.1)
eststo q25:  qcount countagents divided yr_45 yr_sq  divided if lawcounter==1 & year<2017, q(0.25)
eststo q50:  qcount countagents divided yr_45 yr_sq  divided if lawcounter==1 & year<2017, q(0.5)
eststo q75:  qcount countagents divided  yr_45 yr_sq  divided if lawcounter==1 & year<2017, q(0.75)
eststo q90:  qcount countagents divided yr_45 yr_sq  divided if lawcounter==1 & year<2017, q(0.9)

eststo m1b:  qcount countagents yr_45 yr_sq  divided ln_emp if lawcounter==1 & year<2017, q(0.1)
eststo m2b:  qcount countagents yr_45 yr_sq  divided ln_emp if lawcounter==1 & year<2017, q(0.25)
eststo m3b:  qcount countagents yr_45 yr_sq  divided ln_emp if lawcounter==1 & year<2017, q(0.5)
eststo m4b:  qcount countagents yr_45 yr_sq  divided ln_emp if lawcounter==1 & year<2017, q(0.75)
eststo m5b:  qcount countagents yr_45 yr_sq  divided ln_emp if lawcounter==1 & year<2017, q(0.9)

esttab  q10 m1b q25 m2b  q50  m3b q75  m4b q90  m5b, replace se label b(3) se(3) stats(r2 r2_a N) nogaps compress 

log close

